package org.frogs.algo;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.StringTokenizer;

public class HistoryLogger {
	private static final String filename = System.getProperty("user.dir")
			+ "\\data\\history.txt";
	private static final String helpFile = System.getProperty("user.dir")
			+ "\\data\\lastMoves.txt";

	// EnemyFrogLastCoordinates

	// Called by Angel
	public static void logInfo() {
		File lastMoves = new File(helpFile);
		try {
			Scanner scan = new Scanner(lastMoves);
			
			StringTokenizer lastMovesRow = new StringTokenizer (scan.nextLine());
            Double lastEnemyX = Double.parseDouble(lastMovesRow.nextToken());
            Double lastEnemyY = Double.parseDouble(lastMovesRow.nextToken());
            Double currEnemyX = Double.parseDouble(lastMovesRow.nextToken());
            Double currEnemyY = Double.parseDouble(lastMovesRow.nextToken());
            Double lastFrogX = Double.parseDouble(lastMovesRow.nextToken());
            Double lastFrogY = Double.parseDouble(lastMovesRow.nextToken());
            //Double currFrogX = Double.parseDouble(lastMovesRow.nextToken());
            //Double currFrogY = Double.parseDouble(lastMovesRow.nextToken());
      
            Double lastDistance = Utilities.pointToPointDistance(new Point2(lastEnemyX, lastEnemyY), new Point2(lastFrogX, lastFrogY));
            Double currentLastDistance = Utilities.pointToPointDistance(new Point2(currEnemyX, currEnemyY), new Point2(lastFrogX, lastFrogY));
            
            Double currentLineDistance = Utilities.pointToLineDistance(new Point2(lastEnemyX, lastEnemyY), new Point2(lastFrogX, lastFrogY), new Point2(currEnemyX, currEnemyY));
            
            if (currentLineDistance < 0.5) {
            	if (lastDistance > currentLastDistance) {
            		//front
            	} else {
            		//rare
            	}
            } else {
            if ((currentLastDistance) >= (0.95*lastDistance) &&
            		(currentLastDistance) <= (1.05*lastDistance)) {
            	if (currentLineDistance < 0) {
            		//top
            	} else {
            		//bottom
            	}
            } else {
            	if (lastDistance > currentLastDistance) {
            		if (currentLineDistance < 0) {
            			//topFront
            		} else {
            			//bottomFront
            		}
            	} else {
            		if (currentLineDistance < 0) {
            			//topRare
            		} else {
            			//bottomRare
            		}
            	}
            }
            }
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}

	public static void logLine(String line, boolean appendFlag) {
		try {
			PrintWriter out = new PrintWriter(new BufferedWriter(
					new FileWriter(filename, appendFlag)));
			if (appendFlag) {
				out.println(line);
			} else {
				out.print(line);
			}
			out.close();
		} catch (IOException e) {
			// catch or something. Unexpected, cause the input is correct
			// always.
		}
	}

	public static void main(String[] args) {
		System.out.println(filename);
		logLine("Front 34.6", true);
		logLine("FrontTop 33.2", true);
		logLine("Top 34.1", true);
		logLine("Front 33.0", true);
	}
}
